<template>
  <el-menu
      :default-active="getDefaultActive"
      class="el-menu-vertical-demo"
      :style="'width:'+asideWith"
      :collapse="isCollapse">
    <router-link to="dashboard">
      <el-menu-item index="dashboard" @click="selectedMenu({name:'dashboard',title:'首页'})">
        <i class="el-icon-s-home"></i>
        <span slot="title">首页</span>
      </el-menu-item>
    </router-link>

    <el-submenu :index="menu.resourceSeq+''" v-for="menu in getMenuList" :key="menu.id">
      <template slot="title">
        <i :class="menu.resourceIcon"></i>
        <span>{{menu.resourceName}}</span>
      </template>

      <router-link :to="item.resourceUrl" v-for="item in menu.childList" :key="item.id">
        <el-menu-item :index="item.resourceUrl+''" @click="selectedMenu({name:item.resourceUrl,title:item.resourceName})">
          <template slot="title">
            <i :class="item.resourceIcon"></i>
            <span slot="title">{{item.resourceName}}</span>
          </template>
        </el-menu-item>
      </router-link>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  name: "SideMenu",
  data(){
    return{
      menuList:[],
    }
  },
  props:{
    isCollapse: false,//是否收起菜单
    asideWith: '',//宽度
  },
  computed:{
    getDefaultActive(){//获取被选中的sideMenu
      return this.$store.getters.getEditSelected
    },
    getMenuList(){
      return this.$store.getters.getMenuList
    }
  },
  methods:{
    // handleOpen(key, keyPath) {
    //   this.defaultActive = key
    //   console.log(keyPath)
    //   // console.log(key, keyPath);
    // },
    // handleClose(key, keyPath) {
    //   // console.log(key, keyPath);
    // },
    handleClick(key, keyPath){
      console.log(key)
      console.log(keyPath)
    },
    //选中的侧边菜单 点击后 添加头部标签页
    selectedMenu(item){
      this.$store.commit('addTab',item)
    }
  },
}
</script>

<style scoped>
a {
  text-decoration: none;
}
.el-menu-vertical-demo {
  height: 100%;
}
</style>